package com.google.gwt.it2tool.server;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.gwt.it2tool.client.Production;

@PersistenceCapable
public class ProductionJDO {	
	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
		
	@Persistent
	private String id;
	@Persistent
	private String name;
	@Persistent
	private double area;
	@Persistent
	private double productivity;
	@Persistent
	private double duration;	
	
	public ProductionJDO(Production p){
		set(p);
	}
	
	public ProductionJDO(String id, String name, double area, double productivity, double duration) {
		this.id=id;
		this.name = name;
		this.area = area;
		this.duration = duration;
		this.productivity = productivity;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public double getArea() {
		return area;
	}

	public void setArea(int area) {
		this.area = area;
	}
	
	public double getDuration() {
		return duration;
	}

	public void setDuration(int duration) {
		this.duration = duration;
	}

	public double getProductivity() {
		return productivity;
	}

	public void setProductivity(int productivity) {
		this.productivity = productivity;
	}
	
	public String getId(){
		return id;
	}
	
	public void setId(String id){
		this.id=id;
	}
	
	public void set(Production p){
		id=p.getId();
		name=p.getName();
		area=p.getArea();
		productivity=p.getProductivity();
		duration=p.getDuration();
	}
	
	public int getOutput(double massProductionLvl){
		double bonus = ((massProductionLvl*2.5d)/100d)*area;
		double mins = duration/(((area + bonus))/100d)*60d;
		mins = Math.ceil(mins);
		double cycles = 1440d/mins;
		cycles = Math.floor(cycles);
		return (int) ((int)cycles*productivity);
	}
	
}
